import router from '.';
import store from '../store/index';

import '../../static/plug/nprogress/css/nprogress.css';
import NProgress from '../../static/plug/nprogress/js/nprogress'

NProgress.configure({ showSpinner: false })// 去除圈圈gif

const whiteList = ['']//需要登陆验证的path

 
 router.beforeEach((to, from, next) => {
  NProgress.start() // start progress bar
  
  if (store.getters.islogin) { 
   
    if (to.path.toLocaleLowerCase() === '/user/login') {
      next({ path: '/' })
      NProgress.done() // if current page is dashboard will not trigger	afterEach hook, so manually handle it
    } else {
      next()
      NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
    }
  } else {
    if (whiteList.indexOf(to.path) < 0) { // 不在登录名单，直接进入
      next()
    } else {
      next('/User/Login') // 
      NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
    }
  }
})


router.afterEach(() => {
  NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
})
